package com.shopping.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.shopping.model.Admins;

public class AdminInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {

		//是否通过拦截，默认false
//		System.out.println("interceptor。。。。");
		//判断逻辑
		HttpSession session = request.getSession();
		Admins admins=(Admins) session.getAttribute("admins");
		
		//返回处理
		if(admins==null) {
			//没有登录
			//跳转到login页面去
			response.sendRedirect("login.jsp");
			return false;
		}else {
			//登陆了
			return true;
		}
	}

	
}
